#ifndef PHOTOFIELD_H
#define PHOTOFIELD_H

#include "photo_global.h"
#include "../databasefield.h"
#include <QLabel>
#include <QPushButton>
#include <QSqlQuery>

/**
 * @brief The PhotoField class
 *
 * For now, only one object of this class can be created
 * For now, saves loaded photo immediately
 */
class PHOTOSHARED_EXPORT PhotoField : public DatabaseField
{
    Q_OBJECT
    Q_INTERFACES(DatabaseField)
public:
    PhotoField();

    QWidget *createDelegate(const QVariantMap &properties = QVariantMap());

    void setEditable(QWidget *delegate, bool editable);
    QVariant data(QWidget *delegate) const;
    void setData(QWidget *delegate, const QVariant &data);

public slots:
    void clear(QWidget *delegate);

private slots:
    void clearPhoto();
    void editPhoto();

private:
    QSqlQuery sql;
    QPushButton *m_clearButton;
    QPushButton *m_editButton;
    int m_id; // id of loaded photo
    QVector<QLabel *> m_labels;
};

#endif // PHOTOFIELD_H
